home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Workbench Add-On
/
Workbench Add-On - Volume 1.iso
/
BBS-Archive
/
Comm
/
term-source.lha
/
Extras
/
Source
/
term-Source.lha
/
MacroPanel.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-06-17
|
9KB
|
372 lines
/*
** MacroPanel.c
**
** Editing panel for key macro configuration
**
** Copyright © 1990-1995 by Olaf `Olsen' Barthel
** All Rights Reserved
*/
#include "termGlobal.h"
enum { GAD_QUALIFIER=1,GAD_F1,GAD_F2,GAD_F3,GAD_F4,GAD_F5,GAD_F6,GAD_F7,
GAD_F8,GAD_F9,GAD_F10,GAD_USE,GAD_LOAD,GAD_SAVE,GAD_CANCEL };
BOOLEAN __regargs
MacroPanel(struct MacroKeys *MacroKeys,STRPTR LastMacros,BOOLEAN Globals,struct Window *Parent)
{
struct MacroKeys *Keys;
ULONG OldCRC;
BOOLEAN MacroChanged = FALSE;
OldCRC = DoCRC(MacroKeys,sizeof(struct MacroKeys));
if(Keys = (struct MacroKeys *)AllocVecPooled(sizeof(struct MacroKeys),MEMF_ANY))
{
struct LayoutHandle *Handle;
CopyMem(MacroKeys,Keys,sizeof(struct MacroKeys));
if(Handle = LT_CreateHandleTags(Window -> WScreen,
LH_LocaleHook, &LocaleHook,
TAG_DONE))
{
struct Window *PanelWindow;
LT_New(Handle,
LA_Type, VERTICAL_KIND,
TAG_DONE);
{
LT_New(Handle,
LA_Type, VERTICAL_KIND,
LA_LabelID, MSG_V36_0094,
TAG_DONE);
{
LT_New(Handle,
LA_Type, VERTICAL_KIND,
TAG_DONE);
{
LT_New(Handle,
LA_Type, CYCLE_KIND,
LA_LabelID, MSG_MACROPANEL_KEY_MODIFIER_GAD,
LA_ID, GAD_QUALIFIER,
LACY_TabKey, TRUE,
LACY_FirstLabel,MSG_MACROPANEL_NONE_TXT,
LACY_LastLabel, MSG_MACROPANEL_CONTROL_TXT,
TAG_DONE);
LT_New(Handle,
LA_Type, XBAR_KIND,
TAG_DONE);
LT_EndGroup(Handle);
}
LT_New(Handle,
LA_Type, VERTICAL_KIND,
TAG_DONE);
{
STATIC STRPTR Labels[10] =
{
"F _1",
"F _2",
"F _3",
"F _4",
"F _5",
"F _6",
"F _7",
"F _8",
"F _9",
"F1_0"
};
LONG i;
for(i = 0 ; i < 10 ; i++)
{
LT_New(Handle,
LA_Type, STRING_KIND,
LA_LabelText, Labels[i],
LA_Chars, 40,
LA_ID, GAD_F1 + i,
TAG_DONE);
}
LT_EndGroup(Handle);
}
LT_EndGroup(Handle);
}
LT_New(Handle,
LA_Type,VERTICAL_KIND,
TAG_DONE);
{
LT_New(Handle,
LA_Type, XBAR_KIND,
LAXB_FullSize, TRUE,
TAG_DONE);
LT_EndGroup(Handle);
}
LT_New(Handle,LA_Type,HORIZONTAL_KIND,
LAGR_SameSize, TRUE,
LAGR_Spread, TRUE,
TAG_DONE);
{
LT_New(Handle,
LA_Type, BUTTON_KIND,
LA_LabelID, MSG_GLOBAL_USE_GAD,
LA_ID, GAD_USE,
LABT_ReturnKey, TRUE,
LABT_ExtraFat, TRUE,
TAG_DONE);
LT_New(Handle,
LA_Type, BUTTON_KIND,
LA_LabelID, MSG_GLOBAL_LOAD_GAD,
LA_ID, GAD_LOAD,
LABT_ExtraFat, TRUE,
TAG_DONE);
LT_New(Handle,
LA_Type, BUTTON_KIND,
LA_LabelID, MSG_GLOBAL_SAVE_GAD,
LA_ID, GAD_SAVE,
LABT_ExtraFat, TRUE,
TAG_DONE);
LT_New(Handle,
LA_Type, BUTTON_KIND,
LA_LabelID, MSG_GLOBAL_CANCEL_GAD,
LA_ID, GAD_CANCEL,
LABT_EscKey, TRUE,
LABT_ExtraFat, TRUE,
TAG_DONE);
LT_EndGroup(Handle);
}
LT_EndGroup(Handle);
}
if(PanelWindow = LT_Layout(Handle,LocaleString(MSG_MACROPANEL_MACRO_PREFERENCES_TXT),NULL,0,0,IDCMP_CLOSEWINDOW,0,
LAWN_HelpHook, &GuideHook,
LAWN_Parent, Parent,
WA_DepthGadget, TRUE,
WA_CloseGadget, TRUE,
WA_DragBar, TRUE,
WA_RMBTrap, TRUE,
WA_Activate, TRUE,
TAG_DONE))
{
struct IntuiMessage *Message;
BOOLEAN Done = FALSE;
ULONG MsgClass,
MsgQualifier;
UWORD MsgCode;
struct Gadget *MsgGadget;
UBYTE DummyBuffer[MAX_FILENAME_LENGTH],
*DummyChar;
struct FileRequester *FileRequest;
LONG Modifier = 0,i;
GuideContext(CONTEXT_MACROS);
PushWindow(PanelWindow);
LT_ShowWindow(Handle,TRUE);
if(XEmulatorBase && Config -> TerminalConfig -> EmulationMode == EMULATION_EXTERNAL && Globals)
{
ULONG KeyMask = XEmulatorGetFreeMacroKeys(XEM_IO,Modifier);
for(i = 0 ; i < 10 ; i++)
{
LT_SetAttributes(Handle,GAD_F1 + i,
GTST_String, Keys -> Keys[Modifier][i],
GA_Disabled, !(KeyMask & (1L << i)),
TAG_DONE);
}
}
else
{
for(i = 0 ; i < 10 ; i++)
{
LT_SetAttributes(Handle,GAD_F1 + i,
GTST_String, Keys -> Keys[Modifier][i],
TAG_DONE);
}
}
do
{
if(Wait(PORTMASK(PanelWindow -> UserPort) | SIG_BREAK) & SIG_BREAK)
{
CopyMem(Keys,MacroKeys,sizeof(struct MacroKeys));
break;
}
while(Message = (struct IntuiMessage *)GT_GetIMsg(PanelWindow -> UserPort))
{
MsgClass = Message -> Class;
MsgQualifier = Message -> Qualifier;
MsgCode = Message -> Code;
MsgGadget = (struct Gadget *)Message -> IAddress;
GT_ReplyIMsg(Message);
LT_HandleInput(Handle,MsgQualifier,&MsgClass,&MsgCode,&MsgGadget);
if(MsgClass == IDCMP_CLOSEWINDOW)
{
CopyMem(Keys,MacroKeys,sizeof(struct MacroKeys));
Done = TRUE;
}
if(MsgClass == IDCMP_GADGETUP)
{
switch(MsgGadget -> GadgetID)
{
case GAD_QUALIFIER:
for(i = 0 ; i < 10 ; i++)
strcpy(Keys -> Keys[Modifier][i],(STRPTR)LT_GetAttributes(Handle,GAD_F1 + i,TAG_DONE));
Modifier = MsgCode;
if(XEmulatorBase && Config -> TerminalConfig -> EmulationMode == EMULATION_EXTERNAL && Globals)
{
ULONG KeyMask = XEmulatorGetFreeMacroKeys(XEM_IO,Modifier);
for(i = 0 ; i < 10 ; i++)
{
LT_SetAttributes(Handle,GAD_F1 + i,
GTST_String, Keys -> Keys[Modifier][i],
GA_Disabled, !(KeyMask & (1L << i)),
TAG_DONE);
}
}
else
{
for(i = 0 ; i < 10 ; i++)
{
LT_SetAttributes(Handle,GAD_F1 + i,
GTST_String,Keys -> Keys[Modifier][i],
TAG_DONE);
}
}
break;
case GAD_USE:
for(i = 0 ; i < 10 ; i++)
strcpy(Keys -> Keys[Modifier][i],(STRPTR)LT_GetAttributes(Handle,GAD_F1 + i,TAG_DONE));
CopyMem(Keys,MacroKeys,sizeof(struct MacroKeys));
Done = TRUE;
break;
case GAD_LOAD:
strcpy(DummyBuffer,LastMacros);
DummyChar = PathPart(DummyBuffer);
*DummyChar = 0;
LT_LockWindow(PanelWindow);
if(FileRequest = GetFile(PanelWindow,LocaleString(MSG_MACROPANEL_LOAD_MACRO_KEYS_TXT),DummyBuffer,FilePart(LastMacros),DummyBuffer,"#?.prefs",FALSE,FALSE,FALSE,LocaleString(MSG_GLOBAL_LOAD_TXT),TRUE))
{
if(!LoadMacros(DummyBuffer,Keys))
ShowError(PanelWindow,ERR_LOAD_ERROR,IoErr(),DummyBuffer);
else
{
MacroChanged = FALSE;
OldCRC = DoCRC(Keys,sizeof(struct MacroKeys));
strcpy(Config -> FileConfig -> MacroFileName,DummyBuffer);
strcpy(LastMacros,DummyBuffer);
for(i = 0 ; i < 10 ; i++)
{
LT_SetAttributes(Handle,GAD_F1 + i,
GTST_String,Keys -> Keys[Modifier][i],
TAG_DONE);
}
}
FreeAslRequest(FileRequest);
}
LT_UnlockWindow(PanelWindow);
break;
case GAD_SAVE:
strcpy(DummyBuffer,LastMacros);
DummyChar = PathPart(DummyBuffer);
*DummyChar = 0;
LT_LockWindow(PanelWindow);
for(i = 0 ; i < 10 ; i++)
strcpy(Keys -> Keys[Modifier][i],(STRPTR)LT_GetAttributes(Handle,GAD_F1 + i,TAG_DONE));
if(FileRequest = GetFile(PanelWindow,LocaleString(MSG_MACROPANEL_SAVE_MACRO_KEYS_TXT),DummyBuffer,FilePart(LastMacros),DummyBuffer,"#?.prefs",TRUE,FALSE,FALSE,LocaleString(MSG_GLOBAL_SAVE_TXT),TRUE))
{
if(!WriteIFFData(DummyBuffer,Keys,sizeof(struct MacroKeys),ID_KEYS))
ShowError(PanelWindow,ERR_SAVE_ERROR,IoErr(),DummyBuffer);
else
{
strcpy(LastMacros,DummyBuffer);
MacroChanged = FALSE;
OldCRC = DoCRC(Keys,sizeof(struct MacroKeys));
}
FreeAslRequest(FileRequest);
}
LT_UnlockWindow(PanelWindow);
break;
case GAD_CANCEL:
CopyMem(Keys,MacroKeys,sizeof(struct MacroKeys));
Done = TRUE;
break;
}
}
}
}
while(!Done);
PopWindow();
}
LT_DeleteHandle(Handle);
}
FreeVecPooled(Keys);
}
MacroChanged |= (OldCRC != DoCRC(MacroKeys,sizeof(struct MacroKeys)));
return(MacroChanged);
}